package com.jvm;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * CGLib生产大量的类使方法区出现内存溢出异常
 * 方法区用于存放Class的相关信息，如类名、访问修饰符、常量池、字段描述、方法描述等
 * VM Args: -XX:PermSize=10M -XX:MaxPermSize=10M
 * @author zhuangqi
 * @@date 2017/3/30.
 */
public class JavaMethodAreaOOM {
    public static void main(final String[] args) {
        while (true){
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(OOMObject.class);
            enhancer.setUseCache(false);
            enhancer.setCallback(new MethodInterceptor() {
                public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                    return methodProxy.invoke(o,args);
                }
            });
            enhancer.create();
        }
    }
    static class OOMObject{

    }
}
